/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package pe.edu.pucp.cpnc.mm.clientview;


/**
 *
 * @author alulab11
 */
public class MapBtnPanel extends javax.swing.JPanel {
    private MapViewerPanel mainPanel;
    /**
     * Creates new form MapBtnPanel
     * @param p
     */
    public MapBtnPanel(MapViewerPanel p) {
        initComponents();  
        mainPanel = p;
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel2 = new javax.swing.JPanel();
        jTabbedPane4 = new javax.swing.JTabbedPane();
        jtObjetos = new javax.swing.JTabbedPane();
        jPanel1 = new javax.swing.JPanel();
        btnTile1 = new javax.swing.JButton();
        btnTile2 = new javax.swing.JButton();
        jPanel3 = new javax.swing.JPanel();
        btnUnit1 = new javax.swing.JButton();
        jPanel4 = new javax.swing.JPanel();
        btnBuilding1 = new javax.swing.JButton();
        btnBuilding2 = new javax.swing.JButton();
        jPanel5 = new javax.swing.JPanel();

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 100, Short.MAX_VALUE)
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 100, Short.MAX_VALUE)
        );

        btnTile1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/res/ICONS/iconoGrass1.png"))); // NOI18N
        btnTile1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnTile1ActionPerformed(evt);
            }
        });

        btnTile2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/res/ICONS/iconoSand1.png"))); // NOI18N
        btnTile2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnTile2ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(36, 36, 36)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(btnTile2)
                    .addComponent(btnTile1))
                .addContainerGap(45, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(btnTile1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnTile2)
                .addContainerGap(490, Short.MAX_VALUE))
        );

        jtObjetos.addTab("Terrenos", jPanel1);

        btnUnit1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/res/ICONS/iconoEspadachin.png"))); // NOI18N
        btnUnit1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnUnit1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGap(25, 25, 25)
                .addComponent(btnUnit1, javax.swing.GroupLayout.PREFERRED_SIZE, 182, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(29, Short.MAX_VALUE))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(btnUnit1)
                .addContainerGap(491, Short.MAX_VALUE))
        );

        jtObjetos.addTab("Unidades", jPanel3);

        btnBuilding1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/res/ICONS/iconoCasa.png"))); // NOI18N
        btnBuilding1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnBuilding1ActionPerformed(evt);
            }
        });

        btnBuilding2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/res/ICONS/iconoTorreGuardia.png"))); // NOI18N
        btnBuilding2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnBuilding2ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addGap(23, 23, 23)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(btnBuilding1, javax.swing.GroupLayout.PREFERRED_SIZE, 180, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnBuilding2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap(33, Short.MAX_VALUE))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(btnBuilding1)
                .addGap(18, 18, 18)
                .addComponent(btnBuilding2)
                .addContainerGap(298, Short.MAX_VALUE))
        );

        jtObjetos.addTab("Edificios", jPanel4);

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 236, Short.MAX_VALUE)
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 645, Short.MAX_VALUE)
        );

        jtObjetos.addTab("Naturaleza", jPanel5);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jtObjetos, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jtObjetos)
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    private void btnBuilding1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnBuilding1ActionPerformed
        // TODO add your handling code here:
        MapViewerFrame.selectedBuilding = 0;
        MapViewerFrame.selectedTile = -1;
        MapViewerFrame.selectedUnit = -1;
        MapViewerFrame.selectedNature = -1;
        updateSelectedObject();
    }//GEN-LAST:event_btnBuilding1ActionPerformed

    private void btnUnit1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnUnit1ActionPerformed
        // TODO add your handling code here:
        MapViewerFrame.selectedBuilding = -1;
        MapViewerFrame.selectedTile = -1;
        MapViewerFrame.selectedUnit = 0;
        MapViewerFrame.selectedNature = -1;
        updateSelectedObject();
    }//GEN-LAST:event_btnUnit1ActionPerformed

    private void btnTile1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnTile1ActionPerformed
        // TODO add your handling code here:
        MapViewerFrame.selectedBuilding = -1;
        MapViewerFrame.selectedTile = 0;
        MapViewerFrame.selectedUnit = -1;
        MapViewerFrame.selectedNature = -1;
        updateSelectedObject();
    }//GEN-LAST:event_btnTile1ActionPerformed

    private void btnTile2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnTile2ActionPerformed
        // TODO add your handling code here:
        MapViewerFrame.selectedBuilding = -1;
        MapViewerFrame.selectedTile = 1;
        MapViewerFrame.selectedUnit = -1;
        MapViewerFrame.selectedNature = -1;
        updateSelectedObject();
    }//GEN-LAST:event_btnTile2ActionPerformed

    private void btnBuilding2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnBuilding2ActionPerformed
        // TODO add your handling code here:
        MapViewerFrame.selectedBuilding = 2;
        MapViewerFrame.selectedTile = -1;
        MapViewerFrame.selectedUnit = -1;
        MapViewerFrame.selectedNature = -1;
        updateSelectedObject();
    }//GEN-LAST:event_btnBuilding2ActionPerformed

    private void updateSelectedObject(){
        pe.edu.pucp.cpnc.mm.bean.Object obj = null;
        
        if (MapViewerFrame.selectedUnit !=-1)
                    obj = MainWindow.resources.getAvailableUnits().get(MapViewerFrame.selectedUnit);
        else if(MapViewerFrame.selectedBuilding !=-1)
                    obj = MainWindow.resources.getAvailableBuildings().get(MapViewerFrame.selectedBuilding);
        else if(MapViewerFrame.selectedNature !=-1)
                    obj = MainWindow.resources.getAvailableNature().get(MapViewerFrame.selectedNature);
        else if(MapViewerFrame.selectedTile !=-1)        
                    obj = null;
        mainPanel.selObj = obj;
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnBuilding1;
    private javax.swing.JButton btnBuilding2;
    private javax.swing.JButton btnTile1;
    private javax.swing.JButton btnTile2;
    private javax.swing.JButton btnUnit1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JTabbedPane jTabbedPane4;
    private javax.swing.JTabbedPane jtObjetos;
    // End of variables declaration//GEN-END:variables
}
